#include "editpassword.h"
#include "ui_editpassword.h"

editPassWord::editPassWord(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::editPassWord)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::WindowStaysOnTopHint);
    this->setAttribute(Qt::WA_QuitOnClose, false);
    this->setWindowModality(Qt::ApplicationModal);
}

editPassWord::~editPassWord()
{
    delete ui;
}

void editPassWord::on_pushButton_clicked()
{

    QString password=ui->lineEdit->text();
    QRegExp re("[A-Za-z0-9]+");
    if(re.exactMatch(password)&& password.length()==8){
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);

        QString sql=QString("Update IsFirstStartUp set passWord='%1'").arg(password);
        query.exec(sql);

        ui->label_2->setText("请输入8位数字或字母");
        ui->label_2->setStyleSheet("color: rgb(153, 153, 153);");

        this->close();
    }
    else
    {
        ui->label_2->setText("您输入的密码错误");
        ui->label_2->setStyleSheet("color: rgb(255, 0, 0);");
    }
}

void editPassWord::on_pushButton_2_clicked()
{
    ui->label_2->setText("请输入8位数字或字母");
    ui->label_2->setStyleSheet("color: rgb(153, 153, 153);");
    this->close();
}
